Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid a list/array allocation in Task.WhenAll(enumerable) #110536

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

stephentoub
Copy link
Member

When the incoming enumerable isn't a Task[] or List<Task>, we end up allocating either a Task[] or a List<T> (which then may incur one or more array allocations under the covers). We can avoid that by using an internal builder.

Closes #110530

When the incoming enumerable isn't a `Task[]` or `List<Task>`, we end up allocating either a `Task[]` or a `List<T>` (which then may incur one or more array allocations under the covers). We can avoid that by using a builder, either seeded with stack memory for
@stephentoub stephentoub requested a review from Copilot December 17, 2024 00:29
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ValueListBuilder.cs:18

  • The use of the null-forgiving operator (!) on scratchBuffer is unnecessary and potentially misleading. The constructor should ensure that scratchBuffer is non-null before assignment.
_span = scratchBuffer!;

Tip: Leave feedback on Copilot's review comments with the 👎 and 👍 buttons to help improve review quality. Learn more

@stephentoub stephentoub merged commit 144dcae into dotnet:main Dec 17, 2024
137 of 139 checks passed
@stephentoub stephentoub deleted the whenallalloc branch December 17, 2024 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible Task.WhenAll performance improvements
3 participants